﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LoadingPanel : MonoSingleton<LoadingPanel>
{
    Animator animator;
    void Awake()
    {
        animator = GetComponent<Animator>();
        animator.updateMode = AnimatorUpdateMode.UnscaledTime; // 指定该Animator更新模式为不受Time.timeScale影响
    }

    public void Open()
    {
        this.gameObject.SetActive(true);
        Time.timeScale = 0;
        
    }
    
    public void Close()
    {
        this.gameObject.SetActive(false);
    }

    //动画播放结束
    public void Animation_Loading_complete()
    {
        StartCoroutine(wait(0.2f));
    }

    IEnumerator wait(float t)
    {
        yield return new WaitForSecondsRealtime(t);
        
        this.Close();
        Time.timeScale = 1;
    }

    //入场动画播放结束
    public void Animation_Loading_in_complete()
    {
        ShuaiManager.Instance.currentLevelGameObject.SetActive(true);

        GamePanel.Instance.Open();
        GamePanel.Instance.Text_level.text = "关卡-" + ShuaiManager.Instance.level.ToString();
    }

    ////出场动画播放结束
    //public void Animation_Loading_out_complete()
    //{
    //    ShuaiManager.Instance.game_state = GameState.Game;
    //}
}
